package com.yugao.fintech.antelope.mps.controller;

import com.yugao.fintech.antelope.mps.model.rqrs.channel.ChannelResp;
import com.yugao.fintech.antelope.mps.model.rqrs.task.PushTaskListReq;
import com.yugao.fintech.antelope.mps.model.rqrs.task.PushTaskResp;
import com.yugao.fintech.antelope.mps.model.rqrs.task.PushTaskSaveReq;
import com.yugao.fintech.antelope.mps.model.rqrs.task.PushTaskUpdateReq;
import com.yugao.fintech.antelope.mps.service.MsgPushTaskService;
import com.yugao.fintech.antelope.base.ram.ActionType;
import com.yugao.fintech.antelope.base.ram.RamResource;
import com.yugao.fintech.framework.core.response.Resp;
import com.yugao.fintech.framework.security.xss.core.XssCleanIgnore;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "消息推送任务")
@RestController
@RequestMapping("/msgPushTask")
public class PushTaskController {
    @Autowired
    private MsgPushTaskService pushTaskService;

    /**
     * 查询渠道
     */
    @RamResource(action = "msg:channel:query", name = "查询消息推送任务", type = ActionType.READ)
    @GetMapping("/listChannel")
    public Resp<List<ChannelResp>> listChannel() {
        List<ChannelResp> resp = pushTaskService.listChannel();
        return Resp.ok(resp);
    }

    /**
     * 查询消息推送任务
     */
    @GetMapping("/listPushTask")
    @RamResource(action = "msg:pushTask:query", name = "查询消息推送任务", type = ActionType.READ)
    public Resp<List<PushTaskResp>> listPushTask(@Validated PushTaskListReq req) {
        return Resp.ok(pushTaskService.listPushTask(req));
    }
  
    /**
     * 通过id查找 消息推送任务
     */
    @GetMapping("/getPushTask")
    @RamResource(action = "msg:pushTask:query", name = "查询消息推送任务", type = ActionType.READ)
    public Resp<PushTaskResp> getPushTask(@RequestParam(value = "id") Long id) {
        return Resp.ok(pushTaskService.getPushTaskById(id));
    }
  
    /**
     * 保存 消息推送任务
     */
    @PostMapping("/savePushTask")
    @XssCleanIgnore({"tplConfig"})
    @RamResource(action = "msg:pushTask:save", name = " 保存消息推送任务", type = ActionType.WRITE)
    public Resp<?> savePushTask(@Validated @RequestBody PushTaskSaveReq req) {
        return Resp.ok(pushTaskService.saveMsgPushTask(req));
    }
  
    /**
     * 更新 消息推送任务
     */
    @RamResource(action = "msg:pushTask:update", name = "更新消息推送任务", type = ActionType.WRITE)
    @PostMapping("/updatePushTask")
    @XssCleanIgnore({"tplConfig"})
    public Resp<?> updatePushTask(@Validated @RequestBody PushTaskUpdateReq req) {
        return Resp.ok(pushTaskService.updateMsgPushTaskById(req));
    }
  
    /**
     * 批量删除 消息推送任务
     */
    @RamResource(action = "msg:pushTask:delete", name = "删除消息推送任务", type = ActionType.WRITE)
    @DeleteMapping("/batchDeletePushTask")
    public Resp<?> deleteBatch(@RequestParam(value = "ids") List<Long> ids) {
        return Resp.ok(pushTaskService.deletePushTaskByIds(ids));
    }
  
    /**
     * 删除 消息推送任务
     */
    @RamResource(action = "msg:pushTask:delete", name = "删除消息推送任务", type = ActionType.WRITE)
    @DeleteMapping("/deletePushTask")
    public Resp<?> delete(@RequestParam(value = "id") Long id) {
        return Resp.ok(pushTaskService.deletePushTaskById(id));
    }
}
